$(function () {
    var rq = $.getRequest();

    updataOutdoorAqi(rq.id);
    updataMainIndoorAQI(rq.id);
});

function updataOutdoorAqi(id) {
    api.getOutdoorAQI(id, function (d) {
        echart_3(d);
    })
};

function updataMainIndoorAQI(id) {
    api.getMainIndoorAQI(id, function (d) {
        echart_4(d);
    })
};

//室外
function echart_3(data) {

    var xArray = data.map(function (d) {
        return { id: d.fpointNo, name: d.fpointNane, value: d.faqi }
    });

    var yArray = xArray.map(function (d) {
        return d.name;
    });

    var myChart = echarts.init(document.getElementById('chart_3'));
    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '7%',
            top: '10%',
            bottom: '10%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#FFFFFF',
                    fontSize: '10'
                }
            },
            splitLine: {
                show: false,
                lineStyle: {
                    color: ['red']
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#FFFFFF',
                    width: 2, //这里是坐标轴的宽度,可以去掉
                }
            }
        },
        yAxis: {
            type: 'category',
            data: yArray,
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#FFFFFF'
                }
            },
            // y轴的颜色和宽度
            axisLine: {
                lineStyle: {
                    color: '#FFFFFF',
                    width: 1, //这里是坐标轴的宽度
                }
            }
        },
        series: [{
            name: '',
            type: 'bar',
            stack: '数量',
            label: {
                normal: {
                    show: true,
                    position: 'insideRight'
                }
            },
            data: xArray
        }]
    };

    myChart.setOption(option);

    myChart.on('click', function (params) {
        if (params.componentSubType === "bar") {
            if (isNaN(parseInt(params.value))) return;
            var name = encodeURIComponent(params.data.name);
            location.href = `outdoor.html?id=${params.data.id}&name=${name}`;
        }
    });
}

//室内总站
function echart_4(data) {
    var xArray = data.map(function (d) {
        return { id: d.fpointNo, name: d.fpointName, value: d.faqi }
    });

    var yArray = xArray.map(function (d) {
        return d.name;
    });
    var myChart = echarts.init(document.getElementById('chart_4'));
    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '3%',
            right: '7%',
            top: '10%',
            bottom: '10%',
            containLabel: true
        },
        xAxis: {
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#FFFFFF',
                    fontSize: '10'
                }
            },
            splitLine: {
                show: false,
                lineStyle: {
                    color: ['red']
                }
            },
            axisLine: {
                lineStyle: {
                    color: '#FFFFFF',
                    width: 2, //这里是坐标轴的宽度,可以去掉
                }
            }
        },
        yAxis: {
            type: 'category',
            data: yArray,
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#FFFFFF'
                }
            },
            // y轴的颜色和宽度
            axisLine: {
                lineStyle: {
                    color: '#FFFFFF',
                    width: 1, //这里是坐标轴的宽度
                }
            }
        },
        series: [{
            name: '',
            type: 'bar',
            stack: '数量',
            label: {
                normal: {
                    show: true,
                    position: 'insideRight'
                }
            },
            data: xArray
        }]
    };
    myChart.setOption(option);
    myChart.on('click', function (params) {
        if (params.componentSubType === "bar") {
            if (isNaN(parseInt(params.value))) return;
            var name = encodeURIComponent(params.data.name);
            location.href = `indoor.html?id=${params.data.id}&name=${name}`;
        }
    });
}